package com.zkthink.ceres.executor.jobhandler.order;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.zkthink.base.R;
import com.zkthink.ceres.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 订单已发货超过7天，用户还没有确认收货，则定时器自动确认收货
 */
@JobHandler(value = "finishOrderHandler")
@Component
@Slf4j
public class FinishOrderHandler extends IJobHandler {

    @Autowired
    private OrderService orderService;

    @Override
    public ReturnT<String> execute2(String param) throws Exception {
        try{
            R<Integer> result = orderService.autoReceiveGoods();
            if(result.getCode()==0){
                log.info("自动确认收货 成功：完成订单个数"+result.getData());
            }
            return SUCCESS;
        }catch(Exception e){
            log.error("自动确认收货 异常："+e.getMessage(),e);
            return FAIL;
        }
    }

}
